<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/templates/default.xhtml"
	xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">

	<f:metadata>
		<f:viewParam name="year" value="#{successBulletinList.year}"></f:viewParam>
		<f:viewParam name="qClassId"
			value="#{qualificationConditionBean.qualificationClassId}"></f:viewParam>
		<f:viewParam name="sectorId"
			value="#{qualificationConditionBean.sectorId}"></f:viewParam>
		<f:viewParam name="childSectorSno"
			value="#{qualificationConditionBean.childSectorSno}"></f:viewParam>
		<f:viewParam name="certLevel"
			value="#{qualificationConditionBean.certLevel}"></f:viewParam>
		<f:viewParam name="moduleName" value="按月份统计"></f:viewParam>
	</f:metadata>
	<ui:define name="head">
		<h:outputStylesheet name="css/public/tab.css" />
		<h:outputStylesheet name="css/public/table.css" />
	</ui:define>
	<ui:define name="content">
		<h:form>
			<div style="margin: 10px auto;">
				<p:outputLabel value="年份：" style="display:inline-bloack;margin-top:10px;"></p:outputLabel>
				<p:selectOneMenu widgetVar="year"  >
					<f:selectItem itemLabel="2017" itemValue="2017"/>
					<f:selectItem itemLabel="2018" itemValue="2018"/>
					<f:selectItem itemLabel="2019" itemValue="2019" />
					<f:selectItem itemLabel="2020" itemValue="2020"/>
					<f:selectItem itemLabel="2021" itemValue="2021"/>
					<f:selectItem itemLabel="2022" itemValue="2022"/>
					<f:selectItem itemLabel="2023" itemValue="2023"/>
					<f:selectItem itemLabel="2024" itemValue="2024"/>
				</p:selectOneMenu>
				
				<p:outputLabel value=" 资质范围：" style="display:inline-bloack; "></p:outputLabel>
				<p:outputLabel>
					<p:selectOneMenu widgetVar="qualificationClassId">
						<f:selectItem itemLabel="--请选择--" itemValue="#{null}" />
						<f:selectItems value="#{qualificationClassList.resultList}"
							var="_class" itemLabel="#{_class.name}" itemValue="#{_class.id}">
						</f:selectItems>
						<f:ajax render="sectorId certLevel"></f:ajax>
					</p:selectOneMenu>
					#{ ' '}
					<p:commandButton value="查询"  styleClass="queryBtn" ></p:commandButton>
					#{ ' '}
					<p:button value="重置"  ajax="false"
						outcome="BulletinStat.xhtml"></p:button>	
				</p:outputLabel>
			</div>
			<ui:remove>
				<p:commandButton value="导出" ajax="false" style="margin:10px;">
		   			<p:fileDownload value="#{statExport.bulletinStatExport()}" />
		   		</p:commandButton>
	   		</ui:remove>
	   		<p:button styleClass="export" value="导出">	   		
	   		</p:button>
			<table border="1" class="reqTable table">
				<thead>
					<tr>
						<th >月份</th>
						<th >公告数</th>
						<th >累计成交金额(元)</th>
						<th >参与报名次数</th>
					</tr>
				</thead>
				<tbody></tbody>
			</table>
		</h:form>
		<script>
			var contextPath = '${request.getContextPath()}';
			$(function(){	
				$(".queryBtn").click(function(){
					serviceSupplierStat(contextPath);
				});	
				init();

				$(".export").click(function () {
					var year = PF('year').getSelectedValue();
					window.open( contextPath + "/rest/bulletin/bulletinStats/export/" + year );
				});
			})
			// <![CDATA[
			function init(){
				var date = new Date();
				var year = date.getFullYear();
				PF('year').selectValue(year);
				serviceSupplierStat(contextPath);	
			}
			function serviceSupplierStat(contextPath){
				var year = PF('year').getSelectedValue();
			 	var qualificationClassId = PF('qualificationClassId').getSelectedValue();
				var totalCount = 0;
				var url = contextPath+"/rest/bulletin/getBulletinStats?&qualificationClassId="+qualificationClassId+"&year="+year
				$.ajax({
					url:url,
					async:false,
					success:function(data){
						var html = "";
						for(var index in data){
							var stat = data[index];
							html += "<tr>";
								html +="<td>"+stat.dataStr+"</td>";
								html +="<td>"+stat.count+"</td>";
								html +="<td>"+stat.priceCount+"</td>";
								html +="<td>"+stat.appliedCount+"</td>";
							html += "</tr>";
						}
						$(".reqTable").find("tbody").html(html);
						PF('year').selectValue(year);
					}
				});
			}
			// ]]>
		</script>
	</ui:define>
</ui:composition>